package fr.oz.view.profile.dragable.ui 
{
	import caurina.transitions.Tweener;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BitmapFilterQuality;
	import flash.text.TextField;
	import fr.digitas.flowearth.text.styles.styleManager;
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class ColorHandler extends Sprite
	{
		
		public var tf:TextField;
		public var bg:Sprite;
		public var bg_flou:Sprite;
		public var bg_blanc:Sprite;
		
		private var _iselected:Boolean = false;
		private var _selectColor:uint;
		
		public function ColorHandler() 
		{
			if (stage)	init( null );
			else 		addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void 
		{
			mouseChildren = false;
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.REMOVED_FROM_STAGE, dispose);
			tf = new TextField();
			styleManager.applyFormat(tf, ".profile_dragable_clock_bulle");
			addChild(tf);
			tf.x = -18;
			tf.y = -55;
		}
		
		private function dispose(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
			bg_flou.filters = null;
			bg_blanc.filters = null;
			bg.filters = null;
		}
		
		/*	Affichage à l'écran	*/
		public function putName(value:String):void {
			tf.htmlText = value;
		}
		
		/**
		 * Done la valeur à alpha
		 * @param	value
		 */
		public function hideName(value:int = 0):void {
			tf.alpha = value;
		}
		
		/**
		 * Création d'une lueur externe
		 */
		private function select():void {
			Tweener.addTween(bg_flou, { 	_Glow_quality : BitmapFilterQuality.HIGH,
											_Glow_color:_selectColor,
											_Glow_blurX:18,
											_Glow_blurY:18,
											_Glow_strength:3,
											_Glow_alpha:1,
											_Glow_knockout:true,
											time:1,
											delay:.1,
											transition:"easeOutBack"} );
			Tweener.addTween(bg, { 	_Glow_quality : BitmapFilterQuality.HIGH,
											//_Glow_color:_selectColor,
											_Glow_color:0xD1145A,
											_Glow_blurX:12,
											_Glow_blurY:12,
											_Glow_strength:3,
											_Glow_alpha:1,
											delay:.1,
											time:1 } );
			Tweener.addTween(bg_blanc, { 	_Glow_quality : BitmapFilterQuality.HIGH,
											_Glow_color:0xFFE56C,
											//_Glow_color:0xFFFFFF,
											_Glow_blurX:6,
											_Glow_blurY:6,
											_Glow_strength:3,
											_Glow_alpha:1,
											delay:.1,
											time:1 } );
			Tweener.addTween(this, { alpha:.7, scaleX:1.8, scaleY:1.8, time:.5, delay:.1} );
		}
		/**
		 * suppression de la lueur externe
		 */
		private function unselect():void
		{
			Tweener.addTween(this, {alpha:0, scaleX:.6, scaleY:.6, time:.5 } );
			Tweener.addTween(bg_flou, { 	_Glow_quality : BitmapFilterQuality.HIGH,
											_Glow_color:_selectColor,
											_Glow_blurX:0,
											_Glow_blurY:0,
											_Glow_strength:0,
											_Glow_alpha:0,
											time:1,
											onComplete:killFilters } );
			Tweener.addTween(bg_blanc, { 	_Glow_quality : BitmapFilterQuality.HIGH,
											_Glow_color:_selectColor,
											_Glow_blurX:0,
											_Glow_blurY:0,
											_Glow_strength:0,
											_Glow_alpha:0,
											time:1 } );
			Tweener.addTween(bg, { 	_Glow_quality : BitmapFilterQuality.HIGH,
											_Glow_color:_selectColor,
											_Glow_blurX:2,
											_Glow_blurY:2,
											_Glow_strength:0,
											_Glow_alpha:1,
											time:1 } );
		}
		
		private function killFilters():void
		{
			bg_flou.filters = null;
			bg_blanc.filters = null;
			bg.filters = null;
		}
		
		public function chooseColor(color:uint):void {
			_selectColor = color;
			Tweener.addTween(bg, { _color:_selectColor,  time:1 } );
			Tweener.addTween(bg_flou, { _color:_selectColor,  time:1 } );
		}
		
		public function get iselected():Boolean { return _iselected; }
		
		public function set iselected(value:Boolean):void 
		{
			_iselected = value;
			//trace(value);
			if (_iselected)	select();
			else 
			{
				unselect();
			}
		}
		
	}

}